%{
	extern "C"
	{
		int yylex(void);
		int yyerror(const char* str);
		int yywrap();
	}
	#include <stdio.h> 
	#include <stdlib.h>
	#include <vector>
	#include <fstream>	
	#include "tools.hpp"

	
	vector<call_info> dyn_info;	
	call_info dyn_tmp;
    
    vector<agreg_dyn> average_dyn;
    
    vector<merged_info> recap;
	
		vector<static_info> stat_info;
		static_info stat_tmp;
	
%}

%union
{ 
	void* nodeT;
	char* stringT;	
	long int longT;
}

%token CALL ENTRY EXIT NB ID FUNCTION REQUIRED LOADS STORES

%type <stringT>
ID NB

%type <nodeT>
CALL ENTRY EXIT FUNCTION REQUIRED LOADS STORES


%%

Analyse_Traces :
		Fichier_Trace_Statique Fichier_Trace_Dynamique
		;

/** TRACE STATIQUE**/
Fichier_Trace_Statique :
		ListeTracesStatiques
		;

ListeTracesStatiques :
		TraceStatique ListeTracesStatiques		
		| TraceStatique		
		;

TraceStatique :
		FUNCTION ID NB LOADS NB STORES
		{
			stat_tmp.name = $2;
			stat_tmp.nb_loads = atol($3);
			stat_tmp.nb_stores = atol($5);
			stat_info. push_back(stat_tmp);
		}			
		;


/** TRACE DYNAMIQUE**/
Fichier_Trace_Dynamique : 
		ListeTracesDynamiques
		;

ListeTracesDynamiques :
		TraceDynamique ListeTracesDynamiques
		| TraceDynamique
		;

TraceDynamique : 
		CALL NB REQUIRED NB FUNCTION ID ENTRY NB EXIT NB
		{
			// ajout de la trace dans le vecteur
			dyn_tmp.num_appel = atol($2);
			dyn_tmp.required = atoi($4);
			dyn_tmp.name = $6;
			dyn_tmp.start = atol($8);
			dyn_tmp.stop = atol($10);
			dyn_tmp.inclusive_time = atol($10) - atol($8);
			dyn_tmp.exclusive_time = 0;			
			dyn_info.push_back(dyn_tmp);
		}
		;	
		
%%

int yyerror(const char* str)
{
	fprintf(stderr,"Error : %s\n", str);
	exit(0);
}		

int yywrap()
{
	return 1;
}

int main()
{
	while(yyparse());
	
	display_vec(dyn_info);	
	calc_exclusive_times(dyn_info);
	display_vec(dyn_info);
	verif_times(dyn_info);
			
	average_dynamic_infos(dyn_info, average_dyn);
	cout << "average dyn infos";
	display_vec(average_dyn);

	cout << "static infos";
	display_vec(stat_info);

	merge_static_dynamic_infos(average_dyn,stat_info, recap);
	cout << "merged infos";	
	display_vec(recap);
			
	write_comp_data(recap);
	write_data(dyn_info);	
	write_gp(dyn_info);

		
	
	return 0;
}
